package com.example.demo.controller;

import com.example.demo.bean.CmsLink;
import com.example.demo.common.Response;
import com.example.demo.service.CmsLinkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "链接信息管理")
@RequestMapping("/link")
public class CmsLinkController {
    @Autowired
    CmsLinkService linkService;

    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "保存或更新链接信息", notes = "如果传参时指明了链接编号，执行更新操作<br/>"
            + "如果传参时没有指明链接编号，执行插入操作")
    public Response<String> saveOrUpdate(CmsLink link){
        boolean b=linkService.saveOrUpdate(link);
        if(b){
            return Response.ok("操作成功");
        }
        else {
            return Response.error("操作失败");
        }
    }
    @GetMapping("/all")
    @ApiOperation(value = "查询所有链接信息")
    public Response<List<CmsLink>> seleteAll(){
        return Response.ok(linkService.all());
    }
    @DeleteMapping("/deleteById")
    @ApiOperation(value="删除链接信息")
    @ApiImplicitParam(name = "id",value = "要删除的链接编号")
    public Response<String> delete(int id){
        int i=linkService.delete(id);
        if(i>0){
            return Response.ok("删除成功");
        }else {
            return Response.error("删除失败");
        }
    }
    @DeleteMapping("/deleteByIds")
    @ApiOperation(value="批量删除链接信息")
    public Response<String> deleteByIds(int[] ids){
        String s=linkService.deleteByIds(ids);
       return Response.ok(s);
    }

}
